package algorithms.roughgarden.part2.jobsceduler;

import java.util.Comparator;

public class JobDifferenceComparator implements Comparator<Job> {

	public int compare(Job job1, Job job2) {
		int job1HigherPriority = 0;
		int diff1 = job1.getWeight() - job1.getLength();
		int diff2 = job2.getWeight() - job2.getLength();
		if(diff1>diff2){
			job1HigherPriority  = 1;
		}
		else if(diff1 < diff2){
			job1HigherPriority = -1;
		}
		else if(diff1==diff2 ){
			if(job2.getWeight()>job1.getWeight()){
				job1HigherPriority = -1;
			}
			else if(job2.getWeight()<job1.getWeight()){
				job1HigherPriority = 1;
			}
			else{
				job1HigherPriority = 0;
			}
		}
		return job1HigherPriority;
	}

}
